package com.wk.multi;

import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.ReentrantLock;

public class MyRunnable implements Runnable {
    private int n;
    private Semaphore semaphore;
    private ReentrantLock lock;

    public MyRunnable(int n, Semaphore semaphore, ReentrantLock lock) {
        this.n = n;
        this.semaphore = semaphore;
        this.lock = lock;
    }

    @Override
    public void run() {
        try {
            semaphore.acquire(n);
            System.out.println(Thread.currentThread().getName()+ "剩余可用许可证: " + semaphore.availablePermits());
            System.out.println(Thread.currentThread().getName() + "执行完成。。。。");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            semaphore.release(n);
            System.out.println(Thread.currentThread().getName()+ "释放后 可用的许可证: " + semaphore.availablePermits());

        }
    }
}